package com.hzsd.zengbanyi.biaodan_text.bean;

import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

import java.util.ArrayList;

public class UserDAO {
	private  Context context;
	public UserDAO(Context context){
		this.context = context;
	}
	public ArrayList<User> getUserName(String id){		
		DataBaseHelper helper = new DataBaseHelper(context);
		SQLiteDatabase db = helper.getReadableDatabase();
		Cursor cursor = db.query("sys_User", new String[]{"U_CName","UserID","U_LoginName","U_Password","U_EName","U_GroupID"},"U_GroupID=?",new String[]{id} , null, null, null);
		ArrayList<User> listUser = new ArrayList<User>();
		while(cursor.moveToNext()){
		User user =new User();
		user.U_CName = cursor.getString(0);
		user.UserID=cursor.getString(1);
		user.U_LoginName=cursor.getString(2);
		user.U_Password=cursor.getString(3);
		user.U_EName=cursor.getString(4);
		user.U_GroupID=cursor.getString(5);
		listUser.add(user);
		}
		db.close();
		return listUser;
		
	}
	public String getPassword(String name){
		String password=null;
		DataBaseHelper helper = new DataBaseHelper(context);
		SQLiteDatabase db = helper.getReadableDatabase();
		Cursor cursor = db.query("sys_User", new String[]{"U_Password"},"U_CName=?",new String[]{name} , null, null, null);
		ArrayList<User> listUser = new ArrayList<User>();
		while(cursor.moveToNext()){
		
		password=cursor.getString(0);
		}
		db.close();
		return password;
		
	}
	/***
	 * 根据登录名查询用户账号（U_LoginName）
	 * @param name
	 * @return
	 */
	public String getLoginName(String name) {
		String loginname="";
		DataBaseHelper helper=new DataBaseHelper(context);
		SQLiteDatabase db=helper.getReadableDatabase();
		Cursor cursor=db.query("sys_User", new String[]{"U_LoginName"}, "U_CName=?", new String[]{name}, null, null, null);
		while (cursor.moveToNext()) {
			loginname=cursor.getString(0);
		}
		cursor.close();
		db.close();
		return loginname;
		
	}
	/***
	 * 根据登录名查询用户部门ID（U_GroupID）
	 * @param name
	 * @return
	 */
	public String getGroupID(String name) {
		String groupid="";
		DataBaseHelper helper=new DataBaseHelper(context);
		SQLiteDatabase db=helper.getReadableDatabase();
		Cursor cursor=db.query("sys_User", new String[]{"U_GroupID"}, "U_CName=?", new String[]{name}, null, null, null);
		while (cursor.moveToNext()) {
			groupid=cursor.getString(0);
		}
		cursor.close();
		db.close();
		return groupid;
		
	}
}
